﻿using LocoyApp.Locoy.Entry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocoyApp.Locoy
{
    public class MultiPicker : LocoyCode
    {
        /// <summary>
        /// 执行方法，不能修改类和方法名称。
        /// </summary>
        /// <param name="content">标签内容</param>
        /// <param name="response">页面响应，包含了Url、原始Html等属性</param>
        /// <returns>返回处理后的标签内容</returns>
        public string Run(string content, ResponseEntry response)
        {
            var sect1 = "<div class=\"content-box\">";
            var sect2 = "</div>";
            var result = new StringBuilder();
            var offset = 0;
            for (int i = 0; i < 6; i++)
            {
                var start = content.IndexOf(sect1, offset);
                if (start > -1 && start < content.Length)
                {
                    start += sect1.Length;
                    var end = content.IndexOf(sect2, start + 1);
                    if (end > -1 && end < content.Length)
                    {
                        result.Append(content.Substring(start, end - start).Trim());
                        result.Append("<hr />");
                        offset = end + sect2.Length;
                    }
                }
            }

            return result.ToString();
        }
    }
}
